@extends('layouts.console_header')

@section('title', '热搜管理')

@section('resources')
    @parent
    <!-- css 文件 -->
	<link rel="stylesheet" href="{{env('CSS_DOMAIN')}}/css/jquery.dataTables.min.css?v={{env('CSS_VERSION')}}">
    <style>
        .cancel{text-align: center;margin: 5px 10px;}
    </style>
@endsection

@section('content')
<!--  html内容  -->
<section class="user_list">
	<p class="fz_14 account_title"><span style="color: #7f7f7f;"><a href="">首页</a>>用户版运营></span><span class="co_violet">热搜管理</span></p>
	<div class="hot_search_list1">
		<p class="hot_search_list1_title">
			<span class="fl">热词</span>
			<span style="cursor: pointer;" class="fr add_word">+新增</span>
		</p>
		<table>
			<tr>
				<th><span class="order_number">排序</span></th>
				<th>热词名称</th>
				<th>操作</th>
			</tr>
			@foreach($hotwordlists as $list)
			<tr>
				<td>{{$list['sort']}}</td>
				<td>{{$list['name']}}</td>
				<td>
				    <a href="#" onclick="delete_hot_word('{{$list['name']}}')">删除</a>
                @if($list['sort'] != 1)
				    <a href="#" onclick="shift_up('{{$list['name']}}','{{$list['sort']}}')">上移</a>
                @endif
                @if($list['sort'] != count($hotwordlists))
				    <a href="#" onclick="shift_down('{{$list['name']}}','{{$list['sort']}}')">下移</a>
                @endif
                </td>
			</tr>
			@endforeach
		</table>
	</div>
	<div class="hot_search_list1">
		<p class="hot_search_list1_title">
			<span class="fl">近30日热搜排行榜</span>
			{{--<span style="cursor: pointer;" class="fr" id="export_data">导出</span>--}}
		</p>
		<table>
			<tr>
				<th>序号</th>
				<th>搜索词</th>
				<th>热度</th>
				<th>操作</th>
			</tr>
        @foreach($searchlists as $list)
			<tr>
			@if(!isset($j))
				<td>{{$j=1}}</td>
            @else
                <td>{{++$j}}</td>
            @endif
				<td>{{$list['name']}}</td>
				<td>{{$list['count']}}</td>
				<td>
				    <a href="#" onclick="set_hot_word('{{$list['name']}}')">设为热词</a>
                </td>
			</tr>
        @endforeach
		</table>
	</div>
</section>
<div class="hot_search_mark hot_word">
	<p class="oh">
		<span class="fl">热门搜索词</span>
		<img class="fr" src="{{env('IMAGE_DOMAIN')}}/images/close_p.png" alt="">
	</p>
	<p>
		名称：<input type="text" name="name" value="">
	</p>
	<p>
		<button style="background-color: #9955c6;color: #fff;border-radius: 5px;" class="fl" id="hot_word_add">确定</button>
        <button class="cancel fr">取消</button>
	</p>
</div>
@endsection

@section('scriptResources')
    @parent
    <script>
        var cityid = '{{$cityid}}';
        $(document).ready(function() {
            $('.add_word').click(function(){
            	$(".hot_word").show();
            });
            // $(".cancel").click(function(){
            // 	$(".hot_word").hide();
            // });
            $(".hot_word p img").click(function(){
            	$(".hot_word").hide();return;
            });
            //点击保存后触发的事件
            $(".hot_word p img").click(function(){
            	$(".hot_word").hide();return;
            })
        });
        //删除热词
        function delete_hot_word(word) {
            var isconfirm = confirm("确定删除");
            if(isconfirm) {
                $.ajax({
                    url : "/console/user/search/hotword/delete",
                    type : "post",
                    data : {
                        word:word,
                        cityid:cityid
                        },
                    dataType: "json",
                    success:function (data){
                        if(data.status == 'success') {
                            window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                        } else {
                            alert(data.message);
                            $(".doublebtn").hide();return;
                        }
                    }
                });
            }
        }
        //设为热词
        var add_word=null;
        function set_hot_word(word) {
            add_word=word;
            $(".doublebtn").show();
            $(".doublebtn_title").html('提示');
            $(".doublebtn_content").html('确定要设立？');
        }
        $(".sure").click(function(){
            $.ajax({
                url : "/console/user/search/hotword/add",
                type : "post",
                data : {
                    word:add_word,
                    cityid:cityid
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                        $(".doublebtn").hide();return;
                    }
                }
            });
        })
        //新增热词
        $("#hot_word_add").click(function() {
            var word=$("input[name='name']").val();
            $.ajax({
                url : "/console/user/search/hotword/add",
                type : "post",
                data : {
                    word:word,
                    cityid:cityid
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        });
        //上移
        function shift_up(name, sort) {
            $.ajax({
                url : "/console/user/search/hotword/sort/update",
                type : "post",
                data : {
                    name:name,
                    sort:sort,
                    type:'up',
                    cityid:cityid
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        }
        //下移
        function shift_down(name, sort) {
            $.ajax({
                url : "/console/user/search/hotword/sort/update",
                type : "post",
                data : {
                    name:name,
                    sort:sort,
                    type:'down',
                    cityid:cityid
                    },
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        }

        //导出
        $("#export_data").click(function() {
            $.ajax({
                url : "/console/user/search/export",
                type : "get",
                data : {cityid:cityid},
                dataType: "json",
                success:function (data){
                    if(data.status == 'success') {
                        //window.location.href="/console/user/search?cityid=" + cityid + "&now=" + Date.parse(new Date());
                    } else {
                        alert(data.message);
                    }
                }
            });
        });
    </script>
@endsection